class myOpen:
    def __init__(self, file_name, mode):
        self.file = open(file_name, mode)

    def __enter__(self):
        return self.file

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.file.close()


with myOpen("test.txt", "w") as fp:
    fp.write("hello world")
